package com.song.controller.admin;

import com.song.dto.SetmealDTO;
import com.song.dto.SetmealPageQueryDTO;
import com.song.result.PageResult;
import com.song.result.Result;
import com.song.service.SetmealService;
import com.song.vo.SetmealVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController("admin-SetmealController")
@RequestMapping("/admin/setmeal")
public class SetmealController {
    @Autowired
    private SetmealService setmealService;

    //修改套餐接口
    @PutMapping
    public Result updateSetmeal(@RequestBody SetmealVO setmealVO){
        log.info("修改套餐接口,参数：{}",setmealVO);
        setmealService.updateSetmeal(setmealVO);
        return Result.success(null,"套餐数据修改成功");
    }

    //分页查询套餐接口
    @GetMapping("/page")
    public Result<PageResult<SetmealVO>> getSetmealPage( SetmealPageQueryDTO setmealPageQueryDTO){
        log.info("分页查询套餐接口,参数：{}",setmealPageQueryDTO);
        return Result.success(setmealService.getSetmealPage(setmealPageQueryDTO),"分页查询套餐成功");
    }
    //套餐起售、停售
    @PostMapping("/status/{status}")
    public Result setSetmealStatus(@PathVariable Integer status,Long id){
        log.info("套餐起售、停售接口,参数：状态{},套餐id：{}",status,id);
        setmealService.updateSetmealStatus(status,id);
        return Result.success(null,"套餐状态修改成功");
    }

    //批量删除套餐接口
    @DeleteMapping
    public Result deleteSetmeals( List<Long> ids){
        log.info("批量删除套餐接口,参数：{}",ids);
        setmealService.deleteSetmeals(ids);
        return Result.success(null,"套餐批量删除成功");
    }
    //增加套餐接口
    @PostMapping
    public Result addSetmeal(@RequestBody SetmealDTO setmealDTO){
        log.info("增加套餐接口,参数：{}",setmealDTO);
        setmealService.addSetmeal(setmealDTO);
        return Result.success(null,"套餐添加成功");
    }
    //根据id查询套餐接口
    @GetMapping("/{id}")
    public Result<SetmealVO> getSetmealById(@PathVariable Long id){
        log.info("根据id查询套餐接口,参数：{}",id);
        return Result.success(setmealService.getSetmealById(id),"查询成功");
    }
}
